#!/bin/bash
# Author: Redbrother
# Email: 728083668@qq.com
# WebSite: https://help.ubuntu.com/community/LiveCDCustomizationFromScratch
# license: None
set -e
#自定义版本项
ARCH=amd64
RELEASE=bionic
installer_url=http://mirrors.aliyun.com/ubuntu/
IMAGE=ubuntu-$RELEASE

if [ "`whoami`" != "root" ]; then
	echo "User must be root 需要root权限."
	exit 0
fi

if [ "`which mkisofs`" == "" ]; then
	ln -s /usr/bin/genisoimage /usr/bin/mkisofs
fi

############################################

chroot squashfs-root apt clean


# make iso file ; build an iso image
mkdir -p cdimage/casper
rm -f cdimage/casper/*
rm -f $IMAGE.iso
cp -f squashfs-root/boot/vmlinuz-*-generic cdimage/casper/vmlinuz
cp -f squashfs-root/boot/initrd.img-*-generic cdimage/casper/initrd.lz
mksquashfs squashfs-root cdimage/casper/filesystem.squashfs -e boot
chmod +666 -R cdimage/casper
mkdir -p cdimage/.disk
touch cdimage/ubuntu
touch cdimage/.disk/base_installable
echo "full_cd/single"        > cdimage/.disk/cd_type
echo "Ubuntu Remix $RELEASE" > cdimage/.disk/info
cd cdimage && find . -type f -print0 | xargs -0 md5sum | grep -v "\./md5sum.txt" > md5sum.txt && cd ..
mkisofs -o $IMAGE.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -r -V "$IMAGE" -cache-inodes -J -l cdimage/
chmod  +666 $IMAGE.iso
cd cdimage && rm -f ubuntu md5sum.txt  && cd ..
rm -rf cdimage/.disk
rm -rf cdimage/casper/*
echo -e "successfully done"


